//
//  UIButtonViewController.swift
//  swift-practice
//
//  Created by 余振涛 on 2021/7/23.
//

import UIKit

class UIButtonViewController: UIViewController {

    init(withTitle title:String){
        super.init(nibName: nil, bundle: nil)
        self.title = title
        self.view.backgroundColor = .white
    }
    
    required init?(coder: NSCoder) {
        super.init(coder: coder)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        createSubViews()
        // Do any additional setup after loading the view.
    }
    

        
    func createSubViews() {
        let aButton = UIButton(type: .system)
        aButton.frame = CGRect(x: 200, y: 200, width: 200, height: 200)
        aButton.backgroundColor = .blue
        aButton.setTitle("未按下", for: .normal)
        aButton.setTitle("按住了", for: .highlighted)
        
        aButton.layer.shadowColor = UIColor.gray.cgColor
        aButton.layer.shadowOffset = CGSize.init(width: 10, height: 5)
        aButton.layer.shadowRadius = 5
        aButton.layer.shadowOpacity = 1
        aButton.layer.masksToBounds = true
        self.view.addSubview(aButton)
        
        
        let gradientLayer = CAGradientLayer()
        gradientLayer.colors = [UIColor.red.cgColor, UIColor.yellow.cgColor]
        gradientLayer.frame = aButton.bounds
        gradientLayer.startPoint = CGPoint(x: 0, y: 0)
        gradientLayer.endPoint = CGPoint(x: 0, y: 1)
        gradientLayer.locations = [0.1]
        aButton.layer.addSublayer(gradientLayer)
    }
    
    func drawArc() {
        let round = UIBezierPath.init(arcCenter: self.view.center, radius: 10, startAngle: CGFloat(-Double.pi/2), endAngle: CGFloat(Double.pi ) * 3 / 2, clockwise: true)
        let bottomLayer = CAShapeLayer()
        bottomLayer.fillColor = UIColor.clear.cgColor
        bottomLayer.strokeColor = UIColor.green.cgColor
        bottomLayer.path = round.cgPath
        bottomLayer.lineWidth = 5
        self.view.layer.addSublayer(bottomLayer)
    }
    
}
